home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / FindBlanks.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  991 b   |  41 lines

  1. //: C21:FindBlanks.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Demonstrate mem_fun_ref() with string::empty()
  7. #include "../require.h"
  8. #include <algorithm>
  9. #include <list>
  10. #include <string>
  11. #include <fstream>
  12. #include <functional>
  13. using namespace std;
  14.  
  15. typedef list<string>::iterator LSI;
  16.  
  17. LSI blank(LSI begin, LSI end) {
  18.    return find_if(begin, end, 
  19.      mem_fun_ref(&string::empty));
  20. }
  21.  
  22. int main(int argc, char* argv[]) {
  23.   requireArgs(argc, 1);
  24.   ifstream in(argv[1]);
  25.   assure(in, argv[1]);  
  26.   list<string> ls;
  27.   string s;
  28.   while(getline(in, s))
  29.     ls.push_back(s);
  30.   LSI lsi = blank(ls.begin(), ls.end());
  31.   while(lsi != ls.end()) {
  32.     *lsi = "A BLANK LINE";
  33.     lsi = blank(lsi, ls.end());
  34.   }
  35.   string f(argv[1]);
  36.   f += ".out";
  37.   ofstream out(f.c_str());
  38.   copy(ls.begin(), ls.end(), 
  39.     ostream_iterator<string>(out, "\n"));
  40. } ///:~
  41.